package com.cms.jy.draft.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import com.cms.jy.draft.entity.DraftSettings;

/**
 * 草稿设置读取工具类
 * 处理 draft_settings 文件（INI格式）
 */
public class DraftSettingsReader {
    
    /**
     * 读取草稿设置
     * @param filePath 文件路径
     * @return DraftSettings 对象
     * @throws IOException IO异常
     */
    public static DraftSettings readDraftSettings(String filePath) throws IOException {
        DraftSettings settings = new DraftSettings();
        
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                // Skip section headers and empty lines
                if (line.startsWith("[") || line.trim().isEmpty()) {
                    continue;
                }
                
                // Parse key-value pairs
                String[] parts = line.split("=", 2);
                if (parts.length == 2) {
                    String key = parts[0].trim();
                    String value = parts[1].trim();
                    
                    switch (key) {
                        case "draft_create_time":
                            settings.setDraft_create_time(Long.parseLong(value));
                            break;
                        case "draft_last_edit_time":
                            settings.setDraft_last_edit_time(Long.parseLong(value));
                            break;
                        case "real_edit_seconds":
                            settings.setReal_edit_seconds(Integer.parseInt(value));
                            break;
                        case "real_edit_keys":
                            settings.setReal_edit_keys(Integer.parseInt(value));
                            break;
                        case "cloud_last_modify_platform":
                            settings.setCloud_last_modify_platform(value);
                            break;
                    }
                }
            }
        }
        
        return settings;
    }
}